package online.misscl.lsy.controller.front;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import online.misscl.lsy.controller.BaseController;
import online.misscl.lsy.entity.dto.AddVaccineAppointmentDTO;
import online.misscl.lsy.entity.dto.CancelAppointmentDTO;
import online.misscl.lsy.entity.dto.MyAppointmentDto;
import online.misscl.lsy.entity.dto.VerificationAppointmentDTO;
import online.misscl.lsy.entity.dto.vo.TableDataInfoVo;
import online.misscl.lsy.entity.dto.vo.VaccineAppointmentVo;
import online.misscl.lsy.service.VaccineAppointmentService;
import online.misscl.lsy.util.AjaxResult;
import online.misscl.lsy.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 预约订单表 前端控制器
 * </p>
 *
 * @author misscl
 * @since 2023/03/11 11:14
 */
@RestController
@RequestMapping("/front/vaccineAppointment")
@Api(tags = "预约订单模块")
public class VaccineAppointmentController extends BaseController {

    @Autowired
    private VaccineAppointmentService vaccineAppointmentService;

    @ApiOperation("预约疫苗")
    @PostMapping("/addAppointment")
    public AjaxResult addAppointment(@RequestBody AddVaccineAppointmentDTO addVaccineAppointmentDTO) {
        return toAjax(vaccineAppointmentService.addAppointment(addVaccineAppointmentDTO,getUserId()));
    }

    @ApiOperation("取消预约")
    @PutMapping("/cancelAppointment")
    public AjaxResult cancelAppointment(@RequestBody CancelAppointmentDTO cancelAppointmentDTO) {
        return toAjax(vaccineAppointmentService.cancelAppointment(cancelAppointmentDTO,getUserId()));
    }

    @ApiOperation("查看预约订单")
    @GetMapping("/myAppointment")
    public TableDataInfoVo<List<VaccineAppointmentVo>> myAppointment(MyAppointmentDto myAppointmentDto) {
        List<VaccineAppointmentVo> list = vaccineAppointmentService.myAppointment(myAppointmentDto,getUserId());
        Page page = PageUtil.getPages(myAppointmentDto.getPageNum(),myAppointmentDto.getPageSize(),list);
        return getDataTable(page.getRecords(),page.getTotal());
    }

    @ApiOperation("核销预约码")
    @PutMapping("/verificationAppointment")
    public AjaxResult verificationAppointment(@RequestBody VerificationAppointmentDTO verificationAppointmentDTO) {
        return toAjax(vaccineAppointmentService.verificationAppointment(verificationAppointmentDTO,getUserId()));
    }
}
